package com.home.service;/**
 * @author chenxf
 * @date 2022/4/15 15:20
 */

import com.home.annotation.PolicyNewsProcesses;
import com.home.enums.FetchTypeEnum;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author chenxf
 * @date 2022/4/15 15:20
 */
@Service
public class PolicyNewsService {
    Map<FetchTypeEnum, PolicyNewsIface> typeProcessors=new HashMap<>();
    PolicyNewsService(Collection<PolicyNewsIface> processors) {
        Map<FetchTypeEnum, PolicyNewsIface> map = new HashMap<>();
        for (PolicyNewsIface processor : processors) {
            FetchTypeEnum typeEnum = processor.getClass().getAnnotation(PolicyNewsProcesses.class).type();
            map.computeIfAbsent(typeEnum, k -> processor);
        }
        typeProcessors = map;
    }

    public PolicyNewsIface getProcessors(FetchTypeEnum stage) {
        return typeProcessors.get(stage);
    }
}
